﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using PeliGo.DataModel;
using PeliGo.BL;

namespace PeliGo.UI
{
    public partial class frmAdmPelicula : Form
    {
        private PeliculaBL objPeliculaBL;

        public frmAdmPelicula()
        {
            InitializeComponent();
        }

        public void ConfigurarControles(DataGridView dgv)
        {
            dgv.AllowDrop = false;
            dgv.AllowUserToAddRows = false;
            dgv.AllowUserToDeleteRows = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.AllowUserToResizeRows = false;
            dgv.ReadOnly = true;
            dgv.MultiSelect = false;
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }

        void CargarGrilla()
        {
            objPeliculaBL = new PeliculaBL();
            dgvPelicula.DataSource = objPeliculaBL.ListarPelicula();
            dgvPeliculaConfigurar();
        }

        private void dgvPeliculaConfigurar()
        {
            DataGridViewCellStyle csLetras = new DataGridViewCellStyle();
            csLetras.Alignment = DataGridViewContentAlignment.MiddleLeft;

           dgvPelicula.Columns["Genero"].Visible = false;
            dgvPelicula.Columns["NPelicula"].DisplayIndex = 0;
            dgvPelicula.Columns["NPelicula"].HeaderText = "Nombre";
            dgvPelicula.Columns["NPelicula"].Width = 207;
            dgvPelicula.Columns["NPelicula"].DefaultCellStyle = csLetras;
            dgvPelicula.Columns["NPelicula"].HeaderCell.Style = csLetras;

            dgvPelicula.Columns["GeneroId"].Visible = true;
            dgvPelicula.Columns["Estado"].Visible = true; 
         

            dgvPelicula.ClearSelection();
        }
        private void btnNuevo_Click(object sender, EventArgs e)
        {
           frmPelicula frmP = new frmPelicula();
            frmP.midelegado += CargarGrilla;
            frmP.ShowDialog();

        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (dgvPelicula.SelectedRows.Count == 0)
            {
                MessageBox.Show("Por favor, seleccionar una pelicula", "PeliGo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (MessageBox.Show("¿Desea eliminar el registro?", "PeliGo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int PeliculaId = Convert.ToInt32(dgvPelicula.SelectedRows[0].Cells["PeliculaId"].Value);
                objPeliculaBL.EliminarPelicula(PeliculaId);
                CargarGrilla();
            }
        }

        private void frmAdmPelicula_Load(object sender, EventArgs e)
        {
            CargarGrilla();
        }
    }
}
